home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2002 January / PC Answers January 2002.7z / PC Answers January 2002.bin / graphics / freepixl / _SETUP.1 / Profile1.pxl < prev    next >
Text File  |  2000-12-23  |  7KB  |  244 lines

  1. {    Sample PiXCL 4.4 source file. Can be freely copied or adapted. }
  2. Initialize:
  3.      UseCoordinates(PIXEL)
  4.     UseFont("Arial",5,15,NOBOLD,NOITALIC,NOUNDERLINE,0,0,255)
  5.  
  6.     SetColorPalette(GENERATE)
  7.     Title$ = "Profiling Pixel Values and Histograms"
  8.     UseCaption(Title$)
  9.     WinLocate(Title$,200,100,760,550,Res)
  10.     WinShow(Title$,TOPMOST,Res)
  11.     DirGet(SourceDir$)
  12.     SampleBitmap$ = "..\images\brsfc754.bmp"
  13.     State = 0
  14.     UseBrush(SOLID,128,128,128)
  15.  
  16.     InfoMenu(REMOVE)
  17.     SetMenu("File",IGNORE,
  18.         "E&xit",Leave,
  19.         ENDPOPUP,
  20.         "&Help",Help,
  21.         ENDPOPUP,
  22.         "&About",About,
  23.         ENDPOPUP)
  24.     DrawText(100,90,"Click anywhere to start")
  25.     SetMouse(0,40,400,410,Profile,X,Y)
  26.     StatusWindow(ENABLE,BOTTOM,3,180,300,-1,0)
  27.     Toolbar(RAISED,
  28.         PXL_LARGE,
  29.         HISTOGRAM,ENABLED,CHECK,"Toggle Channel Histograms",CreateHistograms, 
  30.         NORMALIZE,  ENABLED, STD,"Normalize Image", Normalizer,
  31.         NEGATIVE,  ENABLED, STD,"Make Negative Image", Inverter,
  32.         HELPINFO,ENABLED,STD,"Show Help",Help, 
  33.         NULL,NULL,SEPARATOR,"",Dummy,
  34.         PXL_PRINT,ENABLED,STD,"Print Client Area scaled to page",PrintClientArea,
  35.         NULL,NULL,SEPARATOR,"",Dummy,
  36.         IMAGEINFO,ENABLED,STD,"About Profiling",About)
  37.     
  38.     ChangeToolbarBtn("",1,DISABLED,Res)
  39.     ChangeToolbarBtn("",4,DISABLED,Res)
  40.  
  41. Wait_for_Input:
  42. Dummy:
  43.     GoSub UpdateTime
  44.     WaitInput(10000)
  45.     Goto Wait_for_Input
  46.  
  47. Leave:
  48.     End
  49.  
  50. About:
  51.     AboutUser("About Profile","PiXCL 4.4 Sample program","")
  52.     Goto Wait_for_Input
  53.  
  54. Normalizer:
  55.     NormalizeImage(Res)
  56.     GetChannel(RED,RedHandle)
  57.     GetChannel(GREEN,GreenHandle)
  58.     GetChannel(BLUE,BlueHandle) 
  59.     DrawBitMap(0,40,SampleBitmap$)
  60.     UpdateHistogram(RedHandle, Histogram1,RECALC_NONCUM,Res)
  61.     UpdateHistogram(GreenHandle, Histogram2,RECALC_NONCUM,Res)
  62.     UpdateHistogram(BlueHandle, Histogram3,RECALC_NONCUM,Res)
  63.     Goto Wait_for_Input
  64.  
  65.  
  66. Inverter:
  67.     InvertImage(Res)
  68.     GetChannel(RED,RedHandle)
  69.     GetChannel(GREEN,GreenHandle)
  70.     GetChannel(BLUE,BlueHandle) 
  71.     DrawBitMap(0,40,SampleBitmap$)
  72.     UpdateHistogram(RedHandle, Histogram1,RECALC_NONCUM,Res)
  73.     UpdateHistogram(GreenHandle, Histogram2,RECALC_NONCUM,Res)
  74.     UpdateHistogram(BlueHandle, Histogram3,RECALC_NONCUM,Res)
  75.     Goto Wait_for_Input
  76.  
  77.  
  78.  
  79. PrintClientArea:
  80.     {identify the current client area, save the bitmap in a temp 
  81.      file, then print the bitmap and delete the temp file}
  82.     TempFile$ = SourceDir$ + "\clientimage.bmp"
  83.     WinGetClientRect("",cx1,cy1,cx2,cy2)  
  84.     cy1 += 32   cy2 -= 28   {ignore the toolbar and statusbar regions}
  85.     SaveRectangle(cx1,cy1,cx2,cy2, TempFile$, BACKGND,Res)
  86.     PrintBitmap(TempFile$,PRINT_PAGERES,Res)
  87.     FileDelete(TempFile$,Res)
  88.     Goto Wait_for_Input
  89.  
  90. CreateHistograms:
  91.     WaitInput(100)
  92.     If State = 0 
  93.         State = 1
  94.         {have to convert to 24 bit color space to show channel histograms}
  95.         DrawBitMap(0,40,SampleBitmap$ ){400x324}
  96.         ConvertColorSpace(RGB24,NONE,Res)
  97.         GetChannel(RED,RedHandle)
  98.         GetChannel(GREEN,GreenHandle)
  99.         GetChannel(BLUE,BlueHandle)
  100.  
  101.         {now create the histograms}
  102.         Histogram(830,100,POPUP, SampleBitmap$,RedHandle,NONCUM,"Red",Histogram1,
  103.              830,260,POPUP, SampleBitmap$,GreenHandle,NONCUM,"Green",Histogram2,
  104.               830,420,POPUP, SampleBitmap$, BlueHandle,NONCUM,"Blue", Histogram3)
  105.         WinSetActive(Title$,Res)
  106.     Else
  107.         State = 0
  108.         Histogram()
  109.     Endif
  110.     Goto Wait_for_Input
  111.  
  112. Profile:
  113.     UseBackground(TRANSPARENT,166,166,166)
  114.     DrawBackGround
  115.     SetMouse(0,40,400,410,Start,X,Y)
  116.     SetRightMouse()
  117.     
  118. Start:
  119.     GoSub UpdateStatusDisplay
  120.     ChangeToolbarBtn("",1,ENABLED,Res)
  121.     ChangeToolbarBtn("",4,ENABLED,Res)
  122.     WaitInput(1) 
  123.     SetColorPalette(GENERATE)
  124.     DrawBitMap(0,40,SampleBitmap$){400x324}
  125.      WaitInput(1)  {let windows catch up}
  126.     DrawStatusWinText(0,SampleBitmap$)
  127.     UseCaption(Title$)
  128.     UsePen(NULL,1,0,0,0)
  129.     UseBrush(SOLID,255,255,255)
  130.  
  131.     DrawEdgeRectangle(400,40,420,364,RAISEDEDGE,ADJUST,LEFT)
  132.  
  133.     DrawEdgeRectangle(408,41,542,126,SUNKENEDGE,ADJUST,RECT)
  134.     DrawEdgeRectangle(408,129,542,214,SUNKENEDGE,ADJUST,RECT)
  135.     DrawEdgeRectangle(408,219,542,304,SUNKENEDGE,ADJUST,RECT)
  136.  
  137.     DrawRectangle(410,43,540,124)
  138.     DrawRectangle(410,131,540,212)
  139.     DrawRectangle(410,221,540,302)
  140.  
  141.     X = 0
  142.     Xg = 411
  143.     MaxR = 0 MinR = 255
  144.     MaxG = 0 MinG = 255
  145.     MaxB = 0 MinB = 255
  146.     UseCursor(WAIT)
  147. Loop:
  148.     GetPixel(X,Y,R,G,B,Res)
  149.     If R > MaxR Then MaxR = R
  150.     If G > MaxG Then MaxG = G
  151.     If B > MaxB Then MaxB = B
  152.  
  153.     If R < MinR Then MinR = R
  154.     If G < MinG Then MinG = G
  155.     If B < MinB Then MinB = B
  156.     X = X + 2
  157.     Xg = Xg + 1
  158.     R = R / 4   G = G / 4   B = B / 4
  159.     UsePen(SOLID,1,0,0,255) Y1 = 123 - B
  160.     DrawLine(Xg,123,Xg,Y1)
  161.  
  162.     UsePen(SOLID,1,0,128,0) Y2 = 211 - G
  163.     DrawLine(Xg,211,Xg,Y2)
  164.  
  165.     UsePen(SOLID,1,255,0,0) Y3 =301 - R
  166.     DrawLine(Xg,301,Xg,Y3)
  167.     If X < 252 Then Goto Loop
  168.     
  169.     DrawNumber(440,44,MinB) DrawNumber(480,44,MaxB)
  170.     DrawNumber(440,132,MinG) DrawNumber(480,132,MaxG)
  171.     DrawNumber(440,222,MinR) DrawNumber(480,222,MaxR)
  172.  
  173.     UsePen(SOLID,1,255,255,255)
  174.     DrawLine(0,Y,400,Y)
  175.  
  176.     UseCursor(ARROW)
  177.     SetRightMouse(410,42,540,124,BluProfile,Xx,Yy,
  178.                    410,130,540,212,GrnProfile,Xx,Yy,
  179.                       410,220,540,302,RedProfile,Xx,Yy)
  180.  
  181.     Goto Wait_for_Input
  182.  
  183.  
  184. Help:
  185.     MessageBox(OK,1,INFORMATION,
  186. "To run this sample program, click anywhere in the window,
  187. and an image is displayed. The line at the X coordinate 
  188. that you clicked is scanned for the display RGB pixel 
  189. values, and three profiles are drawn to the right of the 
  190. image, plus the minimum and maximum values for each color
  191. in the scanned line.
  192.  
  193. The Histogram button toggles the display of the individual 
  194. Red, Green and Blue histograms. The Print button captures 
  195. the current client area and sends it to a selected printer, 
  196. scaled to the current page size.
  197.  
  198. Both are disabled at the start of the program, and enabled 
  199. when the sample image is loaded.
  200.  
  201. This program is best viewed with a 2MB or better video card 
  202. with 16 or 24 bit color mode enabled.",
  203.     "Profiling Pixel values",Res)
  204.  
  205.     Goto Wait_for_Input
  206.  
  207. RedProfile:
  208.     MessageBox(OK,1,EXCLAMATION,
  209. "These are the pixel values read from the display
  210. memory, not from the image file itself.",
  211.     "Profile of the Red pixels.",Res)
  212.     Goto Wait_for_Input
  213.  
  214. GrnProfile:
  215.     MessageBox(OK,1,EXCLAMATION,
  216. "These are the pixel values read from the display
  217. memory, not from the image file itself.",
  218.     "Profile of the Green pixels.",Res)
  219.     Goto Wait_for_Input
  220.  
  221. BluProfile:
  222.     MessageBox(OK,1,EXCLAMATION,
  223. "These are the pixel values read from the display
  224. memory, not from the image file itself.",
  225.     "Profile of the Blue pixels.",Res)
  226.     Goto Wait_for_Input
  227.  
  228. UpdateStatusDisplay:
  229.     Str(X,X$) X$ = X$ + ","  Str(Y,Y$) Y$ = Y$ + " selected."
  230.     Msg$ = X$ + Y$
  231.     DrawStatusWinText(1,Msg$)    
  232.     Return
  233.  
  234. UpdateTime:
  235.     TimeToASCII(LOCAL,WDDDMYYYY,Date$)
  236.     GetLocalTime(n,n,n,n,Hour,Minimum)
  237.     Str(Hour,Hour$)   Hour$ = Hour$ + ":"   
  238.     Str(Minimum,Minimum$)
  239.     If Minimum < 10 Then Minimum$ = "0" + Minimum$
  240.     Minimum$ = Minimum$ + "  "
  241.     TimeString$ = Hour$ + Minimum$
  242.     TimeString$ = TimeString$ + Date$
  243.     DrawStatusWinText(2,TimeString$)
  244.     Return